package com.demo.io.talk2;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

/**
 * @author : YU.TAN
 * @date : 2021/11/15 15:45
 */
public class UdpSendDemo1 {
    public static void main(String[] args) throws Exception {
        //获取连接
        DatagramSocket socket=new DatagramSocket();
        while (true){
             //准备数据
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String readLine = reader.readLine();
            byte[] data = readLine.getBytes();
            DatagramPacket packet = new DatagramPacket(data, 0, data.length, new InetSocketAddress("localhost", 6666));

            //发送数据
            socket.send(packet);

            if ("bye".equals(readLine)){
                break;
            }
        }
        socket.close();
    }
}
